// 回到顶部功能块
window.addEventListener("load", function () {
	$(".iconfont");

	this.window.addEventListener("scroll", function () {
		if (this.scrollY > 1000) {
			$(".iconfont").style.display = "block";
		} else {
			$(".iconfont").style.display = "none";
		}
	});
	//给节点绑定点击事件，点击时实现回到顶部功能；
	const backNode = $(".iconfont");
	console.log(backNode);
	backNode.addEventListener("click", function () {
		window.scrollTo({
			top: 0,
			behavior: "smooth",
		});
	});
});
//头部导航栏
window.addEventListener("load", function () {
	const LinkNodes = $(".navgit");

	LinkNodes.forEach(function (v) {
		v.addEventListener("click", function () {
			LinkNodes.forEach(function (vbor) {
				vbor.classList.remove("active");
			});
			v.classList.add("active");
		});
	});
});
window.addEventListener("load", function () {
	//配置
	const config = {
		selector: "#bannerBg",
		vx: 4, //点x轴速度,正为右，负为左
		vy: 4, //点y轴速度
		height: 2, //点高宽，其实为正方形，所以不宜太大
		width: 2,
		count: 100, //点个数
		color: "0, 0, 0", //点颜色
		stroke: "0,0,0", //线条颜色
		dist: 6000, //点吸附距离
		e_dist: 20000, //鼠标吸附加速距离
		max_conn: 10, //点到点最大连接数
	};
	//调用
	CanvasParticle(config);

	//  banner图扫码测试;

	// console.log($(".textNum"));
	const codeTextNode = $(".codeCheck");

	console.log(codeTextNode);

	let data = [
		{ times: 4000, price: 1200, unitPrice: "0.3000" },
		{ times: 8000, price: 2000, unitPrice: "0.2500" },
		{ times: 40000, price: 8000, unitPrice: "0.2000" },
	];

	//遍历上方数组，获取到其中的键名和键值
	//将结构拼接并渲染（innerHTML方法）到 网页节点$(".codeCheck"）内
	data.forEach(function (value, index) {
		$(
			".codeCheck"
		).innerHTML += `<span class="point textNum ">${value.times}次</span>`;

		$(".textNum")[1].classList.add("active");
	});


	const testNode = $(".textNum");

	testNode.forEach(function (v, i) {
		if (i > 0) {
			v.addEventListener("click", function () {
				//点击时获取到上方数组的每一个属性值，并拼接好html结构渲染到
				//$(".testPriceG")

				testNode.forEach(function (value) {
					value.classList.remove("active");
				}); //排他
				this.classList.add("active");

				
				price(data[i - 1].unitPrice, parseInt(v.textContent));

			});

			function price(sell, testNum) {
				
				

				let praicNum = sell * testNum;
				const testPrice = `<li>￥${praicNum} <span>(约${sell}元/次)，仅限企业实名购买；</span></li>`;

				return ($(".testPriceG").innerHTML = testPrice);

			}
		}
	});





	// api文档，错误参照码部分

	const referNodes = $(".referTitle span");
	const funContNodes = $(".discArea");
	funContNodes[0].style.display = "block";

	referNodes.forEach(function (v, i) {
		
		
		v.addEventListener("click", function () {
			referNodes.forEach(function (value , index) {
				value.classList.remove("active");

                funContNodes[index].style.display = "none"

			});

			this.classList.add("active");
			// 功能介绍版块;
            funContNodes[i].style.display = "block"

			
		})

		if (i > 0) {
			
			funContNodes[i].style.display = "none"

		}

	})

	// API详情页注册按钮按下弹出注册界面
	
	console.log($(".regisNow"))

	$(".regisNow").forEach(function (v) {
		
		v.addEventListener("click", function () {
			
			$(".model").style.visibility = "visible";
			$(".regis-plate").style.visibility = "visible";
			$(".regis-cont").style.visibility = "visible";
			$(".errorName").style.visibility = "visible";
			$(".errorPhoNum").style.visibility = "visible";
			$(".errorPassword").style.visibility = "visible";
       
		})


	})
	//登录注册板块
const inputNode = $(".verify1"); // 获取到用户名输入框的元素节点

//用户名输入框获得焦点时，errorName隐藏
inputNode.addEventListener("focus", function () {
	$(".errorName").style.visibility = "hidden";
});
//用户名输入框失去焦点时判断其长度，从而判断errorName是否隐藏
inputNode.addEventListener("blur", function () {
	let inputStr = `${this.value}`;
	console.log(inputStr.length);
	if (inputStr.length < 6 || inputStr.length > 12) {
		$(".errorName").style.visibility = "visible";
	}
});

//手机号输入框

$(".verify2").addEventListener("focus", function () {
	$(".errorPhoNum").style.visibility = "hidden";
});
$(".verify2").addEventListener("blur", function () {
	let phoNumStr = `${this.value}`;
	if (phoNumStr.length !== 11) {
		$(".errorPhoNum").style.visibility = "visible";
	}
});

//密码框
$(".verify3").addEventListener("focus", function () {
	$(".errorPassword").style.visibility = "hidden";
});
$(".verify3").addEventListener("blur", function () {
	let passwardStr = `${this.value}`;
	if (passwardStr.length < 6 || passwardStr.length > 12) {
		$(".errorPassword").style.visibility = "visible";
	}
});
	
	console.log();
	$(".RegNow").addEventListener("click", function () {
		$(".model").style.visibility = "hidden";
			$(".regis-plate").style.visibility = "hidden";
			$(".regis-cont").style.visibility = "hidden";
			$(".errorName").style.visibility = "hidden";
			$(".errorPhoNum").style.visibility = "hidden";
			$(".errorPassword").style.visibility = "hidden";

	})
	
	
	






















});
